import axios from 'axios'

export const baseURL = 'http://121.89.205.189:3000/api'//接口的基路径(有代理必须把axios的基路径去掉)
const request = axios.create({
    baseURL: baseURL,//基路径
    timeout: 6000,//超时
})

//请求之前做什么
request.interceptors.request.use((res) => {
    //尝试是否能获取到localstorage里的token
    const userToken = localStorage?.getItem('userToken')
    //将获取到的token带入请求头
    res.headers.token = userToken
    return res
})

export default request 